<template>
    <div class="show-contain"
         :class="[compOption.isClick && mode == 'sheji' ? 'active-bordert' : '',mode == 'sheji' ? 'widget-item' : '']"
         @click.stop="clickToggleBg">
        <div style="display: flex;align-items: center;width: 100%;margin-bottom: 10px">
            <div class="required-title" v-if="mode != 'sheji' && compOption.options.required">*</div>
            <div class="sort-style" style="top: -5px" v-if="prentCompOption.isChildSort && prentCompOption.isPrentAndChildSort">
                {{ prentCompOption.sortTitle + '.' + (childInd + 1) }}
            </div>
            <div class="sort-style" style="top: -5px" v-else-if="prentCompOption.isChildSort">{{ childInd + 1 }}</div>
            <div class="sort-style" style="top: -5px" v-else-if="prentCompOption.isPrentAndChildSort">{{ prentCompOption.sortTitle }}
            </div>
            <div class="title-openEdit" @click.stop="openTitleEditor(compOption.displayName)"
                 v-html="mode == 'sheji' ? compOption.displayName : compOption.displayName + (compOption.options.totalSource == 0 ? '' :  ` <span style='width:80px;align-self: flex-end'>(${compOption.options.totalSource}) 分</span>`)"
                 :style="{border:mode == 'sheji' ? '1px solid rgba(204, 200, 200, 0.5)' : 'none',padding:mode == 'sheji' ? '10px' : '0',
           }" style="font-size: 18px"></div>
            <div style="margin-left: 10px" v-if="compOption.isClick && mode == 'sheji'">
                <div class="flex-row">
<!--                    <span class="el-icon-rank font-color-main" style="margin-right: 10px"></span>-->
                    <!--                    <span class="el-icon-document-copy font-color-main" style="margin-right: 10px"></span>-->
                    <span class="el-icon-delete font-color-main" @click="delSourceZu"></span>
                </div>
            </div>
        </div>
        <div  style="margin-bottom: 10px;width: 100%" v-if="mode == 'yulan' && (compOption.options.score !==null && compOption.options.score != '不适用')">
            <el-row style="display: flex;align-items: center">
                <el-col :span="1">
                    <div>已得</div>
                </el-col>
                <el-col :span="3">
                    <el-input v-model="compOption.options.score"  class="el-border-dev"
                              :disabled="sourceMode == 'yulan'"></el-input>
                </el-col>
                <el-col :span="2">
                    <div>分</div>
                </el-col>
            </el-row>
        </div>
        <div v-if="compOption.options.questionStem" :style="{marginBottom: mode == 'sheji' ? '10px' : '20px'}"
             style="width: 100%">
            <el-input v-model="compOption.options.placeholderContent" v-if="mode == 'sheji'"
                      placeholder="请输入题干说明"
                      style="width: 100%"></el-input>
            <div v-else class="tigan">
                {{ compOption.options.placeholderContent }}
            </div>
        </div>

        <div v-if="mode == 'sheji'" style="width: 100%;margin-bottom: 10px">
            <el-input v-model="compOption.options.questionStemContent" ></el-input>
        </div>
        <div v-else class="div-outline" style="font-size: 14px;margin-bottom: 10px;width: 100%;padding-left: 5px;
color: #999"
        >
            {{ compOption.options.questionStemContent }}
        </div>
        <div style="width:100%;margin-bottom: 10px;padding-left: 5px;flex-wrap: wrap;justify-content: space-between"
             class="flex-row"
             @click="clickActive"
        ref="prantNum">
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 0 ? 'active-box' : '']">0</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 1 ? 'active-box' : '']">1</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 2 ? 'active-box' : '']">2</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 3 ? 'active-box' : '']">3</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 4 ? 'active-box' : '']">4</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 5 ? 'active-box' : '']">5</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 6 ? 'active-box' : '']">6</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 7 ? 'active-box' : '']">7</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 8 ? 'active-box' : '']">8</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 9 ? 'active-box' : '']">9</div>
            <div class="box-hezi cursor-pointer" :class="[compOption.options.value == 10 ? 'active-box' : '']">10</div>
        </div>
        <div style="width: 100%;padding-left: 5px;justify-content: space-between" class="flex-row">
            <div style="font-size: 12px;color: #999">不可能</div>
            <div style="font-size: 12px;color: #999">极有可能</div>
        </div>
        <div v-if="mode != 'sheji'" style="margin-top: 10px;width: 100%">
            <render-remark :comp-option="compOption" :mode="mode"></render-remark>
        </div>
        <dialog-editor ref="dialogEditor" @throwHtml="(html) => compOption.displayName = html"></dialog-editor>
    </div>
</template>
<script>
import {openEditor} from '@/minexs/index'
import {methodRef} from '@/components/form-designer/widget-panel/main-comp-panal/methodRef'
import RenderRemark from "@/components/renderRemark/renderRemark.vue";
export default {
    name: "NPS-editor",
    components: {RenderRemark},
    mixins:[openEditor,methodRef],
    props: {
        compOption: {
            type: Object,
        },
        prentCompOption: {
            type: Object,
        },
        childInd: {
            type: Number
        },
        mode: {
            type: String,
            default: 'sheji'
            /**
             * sheji
             * xiezuo
             * yulan
             * */
        },
        sourceMode:{
            type:String,
            default:'yulan'
        }
    },
    mounted() {
        this.$nextTick(()=>{
            if (this.mode != 'sheji' && this.compOption.options.value) {
                const childArr = Array.from(this.$refs.prantNum.childNodes);
                let ind = 0;
                for(let val of childArr){
                    if(val.innerText == this.$props.compOption.options.value){
                        this.clickCloneActive(this.$refs.prantNum.childNodes[ind])
                        break
                    }
                    else{
                        ind = ind + 1
                        continue
                    }
                }
            }
        })
    },
    methods: {
        clickToggleBg() {
            if (this.$props.mode == 'sheji') this.$emit('changeClick', this.$props.compOption.id, this.$props.prentCompOption.id)
        },
        clickCloneActive(e) {
            console.log(e,'e')
            let target = null
            if(e.target){
                target = e.target
            }
            else{
                target = e
            }
            if (Number.isInteger(target.innerText * 1)) {
                this.$props.compOption.options.value = target.innerText * 1
            }
        },
        clickActive(e) {
            if(this.mode == 'yulan' || this.compOption.options.readOnly) return
            console.log(e,'e')
            let target = null
            if(e.target){
                target = e.target
            }
            else{
                target = e
            }
            if (Number.isInteger(target.innerText * 1)) {
                this.$props.compOption.options.value = target.innerText * 1
            }
        },
        delSourceZu(){
            this.$confirm('是否确认删除当前问题', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                const ind = this.prentCompOption.widgetList.findIndex(item => item.id == this.compOption.id)
                if(ind != -1){
                    this.prentCompOption.widgetList.splice(ind,1)
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }
            })
        }
    }

}
</script>

<style scoped lang="scss">
.widget-item {
  border: .5px solid #e5e5e5;
  border-radius: 3px;
  padding: 20px;
}

.box-hezi {
  width: 75px;
  height: 28px;
  text-align: center;
  line-height: 28px;
  border-radius: 4px;
  font-size: 14px;
  background: #f1f3f680;
  color: #424141;

  &:hover {
    color: #00c29a;
  }
}

.active-box {
  background: #00c29a;
  color: #fff;
}
</style>
